import { ReqPage, ResPage } from '@/api/interface'
import { TBY } from '@/api/config/servicePort'
import http from '@/api'

export namespace ConfigInfo {
  /**查询参数 */
  export interface Query extends ReqPage {
    code?: string
  }

  /**列表内容 */
  export interface Record {
    id: number
    code: string
    content: string
  }

  /**详情 */
  export interface Form {
    id: number
    code: string
    content: string
  }
}

// 分页查询
export const pageConfigInfo = (params: ConfigInfo.Query) => {
  return http.get<ResPage<ConfigInfo.Record>>(TBY + `/config/page`, params)
}

// 列表查询
export const listConfigInfo = (params: ConfigInfo.Query) => {
  return http.get<ConfigInfo.Record[]>(TBY + `/config/list`, params)
}

// 详情信息
export const getConfigInfoDetail = (id: number) => {
  return http.get<Partial<ConfigInfo.Form>>(TBY + `/config/get`, { id }, { loading: false })
}

// 新增或修改
export const saveOrUpdateConfigInfo = (params: Partial<ConfigInfo.Form>) => {
  return http.post(TBY + `/config/save`, params)
}

// 删除
export const removeConfigInfo = (id: number) => {
  return http.delete(TBY + `/config/delete`, { id })
}

// 验证设备编码是否存在
export const codeExist = (code: string, id?: number) => {
  return http.get<boolean>(TBY + '/config/exist', { code, id }, { loading: false })
}
